package net.uzen.office.test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.uzen.office.test.model.Product;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

public class ProductFormController extends SimpleFormController {
	public ProductFormController() {
		setCommandClass(Product.class);
		setCommandName("product");
		setFormView("test/edit");
	}

	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		System.out.println("command >> " + command);
		return edit(request, response, command, errors);
	}
	
	protected ModelAndView edit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		System.out.println("edit >> " + command);
		ModelAndView mav = new ModelAndView();
		mav.addObject("product", (Product) command);
		return mav;
	}
}
